package com.macrounion.atv.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;


@Configuration
public class WebAppConfig extends WebMvcConfigurerAdapter {

	@Autowired
	private WebApiInterceptor webApiInterceptor;

	@Autowired
	private FileConfig fileConfig;
	
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(webApiInterceptor).addPathPatterns("/web/**","/api/**")
													 .excludePathPatterns("/api/login/**","/swagger-resources/**","/v2/**")
													 .excludePathPatterns("/login","/logout","/error","/web/reg/**","/api/reg/**"
															 ,"/api/settings/getSettings/**");
//		registry.addInterceptor(webApiInterceptor).addPathPatterns("/api/**")
//													.excludePathPatterns("/api/user/regist","/api/user/login","/api/payednotify/**","/api/file/**")
//													;
	}

	/**
	 * 添加静态资源
	 */
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		// 访问myres 文件夹中的test.jpg 图片的地址为 http://localhost:8080/myres/test.jpg
		registry.addResourceHandler("/uploads/**").addResourceLocations("file:"+fileConfig.getUploadFileDir());
		super.addResourceHandlers(registry);
	}
}
